﻿#region Namespace References

using System;
using DynConDevCorp.OpenArch.SmartData.Interfaces.EventArgClasses;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#endregion

namespace UnitTest.DynConDevCorp.OpenArch.SmartData.FunctionalTests
{
    [TestClass]
    public class InvoiceType_FunctionalTests
    {
        #region Public Instance Properties

        public TestContext TestContext
        {
            get { return testContextInstance; }
            set { testContextInstance = value; }
        }

        #endregion

        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup]
        //public void MyTestCleanup()
        //{
        //}
        //

        #region Public Instance Methods

        [TestMethod]
        public void General_FunctionalTest()
        {
            Invoice invoice = new Invoice();
            invoice.InvoiceNumber.Value = "1000";
            invoice.TaxRate.Value = 0.07M;
            invoice.ShippingRate.Value = 1.23M;
            invoice.FieldValueChanged += Invoice_FieldChanged;

            invoice.Items.CollectionChanged += Items_CollectionChanged;

            InvoiceLineItem invoiceLineItem = new InvoiceLineItem();
            Console.WriteLine("Creating Item:  Qty = 10, UnitPrice = $19.95 Weight = 0.75 Lbs");
            invoiceLineItem.Quantity.Value = 10;
            invoiceLineItem.UnitPrice.Value = 19.95M;
            invoiceLineItem.Weight.Value = 0.75M;
            invoice.AddItem(invoiceLineItem);

            invoiceLineItem.FieldValueChanged += InvoiceLineItem_FieldChanged;
            invoiceLineItem.Quantity.Value = 15;
            invoiceLineItem.UnitPrice.Value = 14.95M;
        }

        #endregion

        #region Private Static Methods

        private static void Invoice_FieldChanged(object sender, FieldValueChangedEventArgs e)
        {
            Invoice invoice = sender as Invoice;
            Assert.IsNotNull(invoice);
        }

        ////private static void InvoiceLineItem_Changed(object sender, ValueChangedEventArgs<object> e)
        ////{
        ////    InvoiceLineItem invoiceLineItem = sender as InvoiceLineItem;
        ////    Assert.IsNotNull(invoiceLineItem);
        ////}

        private static void InvoiceLineItem_FieldChanged(object sender, FieldValueChangedEventArgs e)
        {
            InvoiceLineItem invoiceLineItem = sender as InvoiceLineItem;
            Assert.IsNotNull(invoiceLineItem);
        }

        private static void Items_CollectionChanged(object sender, CollectionChangedEventArgs e)
        {
            InvoiceLineItem invoiceLineItem = e.Item as InvoiceLineItem;
            Assert.IsNotNull(invoiceLineItem);
        }

        #endregion

        #region Fields and Constants

        private TestContext testContextInstance;

        #endregion
    }
}